// pages/science/detail/detail.js
import { request } from '../../../request/index.js'
Page({
  data: {
    pet: {
      id: '1',
      name: '英国短毛猫',
      nickName: '蓝猫',
      pic: 'https://img.yzcdn.cn/vant/cat.jpeg',
      hairColor: '蓝色',
      hairSize: '短毛',
      size: '中型',
      minAge: '12',
      maxAge: '15',
      origin: '英国',
      minWeight: '4',
      maxWeight: '8',
      capabilities: '宠物',
      baseInfo: ` 英国短毛猫,哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇`,
      conservation: `耐心照顾`,
    },
    active: 2,
    hasValue: false,
  },

  onChange(event) {
    // wx.showToast({
    //   title: `切换到标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
  },

  onLoad: function(options) {
    const token = wx.getStorageSync('token');
    let that = this;
    this.setData({category: options.category});
    request({
      url: '/pet/getInfoByCategory?category=' + options.category,
      method: 'GET',
      header: {
        'author': token ? token : '',
      }
    }).then(res => {
      if (res.code === 0){
        that.setData({
          hasValue: true,
          pet: res.data,
        })
        if (res.data.size === 'Small') {
          that.setData({pet: {...that.data.pet, size: '小型'}})
        }else if (res.data.size === 'Medium') {
          that.setData({pet: {...that.data.pet, size: '中型'}})
        }else if (res.data.size === 'Large') {
          that.setData({pet: {...that.data.pet, size: '大型'}})
        }else if (res.data.size === 'Extra Large') {
          that.setData({pet: {...that.data.pet, size: '超大型'}})
        }
      } else {
        that.setData({
          hasValue: false,
        })
      }
    })
  }
})